package gloridifice.watersource.registry;

import gloridifice.watersource.WaterSource;
import net.minecraft.fluid.FlowingFluid;
import net.minecraft.fluid.Fluid;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.ForgeFlowingFluid;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public final class FluidRegistry extends RegistryModule{

    public static final ResourceLocation STILL_FLUID_TEXTURE = new ResourceLocation(WaterSource.MODID, "block/fluid/water_still");
    public static final ResourceLocation FLOWING_FLUID_TEXTURE = new ResourceLocation(WaterSource.MODID,"block/fluid/water_flow");

    //public static final Fluid PURIFIED_WATER = new WSFluid("purified_water", STILL_FLUID_TEXTURE, FLOWING_FLUID_TEXTURE, createBuilder(1000, 1000, 0x3ABDFF), -1, true);
    //public static final Fluid SOUL_WATER = new WSFluid("soul_water", STILL_FLUID_TEXTURE, FLOWING_FLUID_TEXTURE, createBuilder(1000, 1000,0x876D5F), -1, true);
    //public static final Fluid COCONUT_MILK = new WSFluid("coconut_milk", STILL_FLUID_TEXTURE, FLOWING_FLUID_TEXTURE, createBuilder(1000, 1000, 0xEAE8E1), -1, true);

    //public static final Fluid PURIFIED_WATER = createSource("purified_water", FluidRegistry.PURIFIED_WATER_PROPERTIES);
    //public static final Fluid PURIFIED_WATER_FLOWING = createFlowing("purified_water_flowing", FluidRegistry.PURIFIED_WATER_PROPERTIES);
    //public static final Fluid SOUL_WATER = createSource("soul_water", FluidRegistry.SOUL_WATER_PROPERTIES);
    //public static final Fluid SOUL_WATER_FLOWING = createFlowing("soul_water_flowing", FluidRegistry.SOUL_WATER_PROPERTIES);
    //public static final Fluid COCONUT_MILK = createSource("coconut_milk", FluidRegistry.COCONUT_MILK_PROPERTIES);
    //public static final Fluid COCONUT_MILK_FLOWING = createFlowing("coconut_milk_flowing", FluidRegistry.COCONUT_MILK_PROPERTIES);

    public static final DeferredRegister<Fluid> FLUIDS = DeferredRegister.create(ForgeRegistries.FLUIDS, WaterSource.MODID);

    public static RegistryObject<FlowingFluid> PURIFIED_WATER = FLUIDS.register("purified_water", () -> {
        return new ForgeFlowingFluid.Source(FluidRegistry.PURIFIED_WATER_PROPERTIES);
    });
    public static RegistryObject<FlowingFluid> PURIFIED_WATER_FLOWING = FLUIDS.register("purified_water_flowing", () -> {
        return new ForgeFlowingFluid.Flowing(FluidRegistry.PURIFIED_WATER_PROPERTIES);
    });
    public static RegistryObject<FlowingFluid> SOUL_WATER = FLUIDS.register("soul_water", () -> {
        return new ForgeFlowingFluid.Source(FluidRegistry.SOUL_WATER_PROPERTIES);
    });
    public static RegistryObject<FlowingFluid> SOUL_WATER_FLOWING = FLUIDS.register("soul_water_flowing", () -> {
        return new ForgeFlowingFluid.Flowing(FluidRegistry.SOUL_WATER_PROPERTIES);
    });
    public static RegistryObject<FlowingFluid> COCONUT_MILK = FLUIDS.register("coconut_milk", () -> {
        return new ForgeFlowingFluid.Source(FluidRegistry.COCONUT_MILK_PROPERTIES);
    });
    public static RegistryObject<FlowingFluid> COCONUT_MILK_FLOWING = FLUIDS.register("coconut_milk_flowing", () -> {
        return new ForgeFlowingFluid.Flowing(FluidRegistry.COCONUT_MILK_PROPERTIES);
    });

    public static ForgeFlowingFluid.Properties PURIFIED_WATER_PROPERTIES =
            new ForgeFlowingFluid.Properties(PURIFIED_WATER, PURIFIED_WATER_FLOWING,
                    FluidAttributes.builder(STILL_FLUID_TEXTURE, FLOWING_FLUID_TEXTURE).color(0x3ABDFF).viscosity(1000))
                    .slopeFindDistance(3)
                    .explosionResistance(100F)
                    .bucket(() -> ItemRegistry.PURIFIED_WATER_BUCKET)
                    .block(() -> BlockRegistry.BLOCK_COCONUT_JUICE_FLUID);
    public static ForgeFlowingFluid.Properties SOUL_WATER_PROPERTIES =
            new ForgeFlowingFluid.Properties(SOUL_WATER, SOUL_WATER_FLOWING,
                    FluidAttributes.builder(STILL_FLUID_TEXTURE, FLOWING_FLUID_TEXTURE).color(0x876D5F).viscosity(1000))
                    .slopeFindDistance(3)
                    .explosionResistance(100F)
                    .bucket(() -> ItemRegistry.SOUL_WATER_BUCKET)
                    .block(() -> BlockRegistry.BLOCK_SOUL_WATER_FLUID);
    public static ForgeFlowingFluid.Properties COCONUT_MILK_PROPERTIES =
            new ForgeFlowingFluid.Properties(COCONUT_MILK, COCONUT_MILK_FLOWING,
                    FluidAttributes.builder(STILL_FLUID_TEXTURE, FLOWING_FLUID_TEXTURE).color(0xEAE8E1).viscosity(1000))
                    .slopeFindDistance(3)
                    .explosionResistance(100F)
                    .bucket(() -> ItemRegistry.COCONUT_MILK_BUCKET)
                    .block(() -> BlockRegistry.BLOCK_COCONUT_JUICE_FLUID);
    protected static ForgeFlowingFluid.Source createSource(String regName, ForgeFlowingFluid.Properties properties){
        ForgeFlowingFluid.Source fluid = new ForgeFlowingFluid.Source(properties);
        fluid.setRegistryName(regName);
        return fluid;
    }
    protected static ForgeFlowingFluid.Flowing createFlowing(String regName, ForgeFlowingFluid.Properties properties){
        ForgeFlowingFluid.Flowing flowingFluid = new ForgeFlowingFluid.Flowing(properties);
        flowingFluid.setRegistryName(regName);
        return flowingFluid;
    }
}
